package com.doudanhua.basecode.jackson.configurer;

import com.doudanhua.basecode.jackson.time.DateTimeConverter;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.util.Date;

/**
 * @Author zhangqian
 * @Description TODO
 * @Date 2022/11/4 17:24
 */
public class DateModelSerializer extends JsonSerializer<Date> {
    private DateTimeConverter _dateConverter;

    public DateModelSerializer(DateTimeConverter dateConverter) {
        this._dateConverter = dateConverter;
    }

    @Override
    public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String result = _dateConverter.format(date);
        jsonGenerator.writeString(result);
    }
}
